home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 21.2 KB | 631 lines | [TEXT/MPS ] |
- // UControl.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UCONTROL__
- #define __UCONTROL__
-
- // MacApp
-
- // Included for gSystemStyle
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UTRACKER__
- #include "UTracker.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- // Toolbox
-
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TScroller;
- class TToolboxEvent;
- class TList;
-
- //----------------------------------------------------------------------------------------
- // TControl: An abstract class that represents a control.
- //----------------------------------------------------------------------------------------
-
- class TControl : public TView
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialize and Free
- //------------------------------------------------------------------------------------
-
- TControl();
- // Constructor
- virtual ~TControl();
- // Destructor
-
- void IControl(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const TextStyle& itsTextStyle = gSystemStyle);// control's text style
- // Initialize a control procedurally.
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFields(TStream* aStream); // override
-
- virtual void WriteFields(TStream* aStream); // override
-
- //------------------------------------------------------------------------------------
- // View method overrides
- //------------------------------------------------------------------------------------
-
- virtual void ComputeFrame(VRect& newFrame);
- // Called to compute the control's size.
-
- virtual Boolean ContainsMouse(const VPoint& theMouse);
- // Returns true if 'theMouse is currently in the controls area.
-
- virtual void ControlArea(VRect& theArea);
- // Returns in 'theArea' the controls active area.
-
- virtual CRect ControlQDArea();
- // Returns in 'theArea' the controls active area (in QD coordinates).
-
- virtual void Dim();
- // dims the current image in the TControl
-
- virtual void DimState(Boolean state, Boolean redraw);
- // If we are not currently dimmed then set fDimmed to 'state.and if 'redraw' is
- // true then call DrawContents.
-
- virtual void DoMouseCommand(VPoint& theMouse, TToolboxEvent* event,
- CPoint hysteresis);
- // Creates a control tracker command, which is posted.
-
- virtual void DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event);
- // Handles the mTurnOn, mTurnOff and mToggle messages by adjusting highlighting
-
- virtual Boolean Focus();
- // Calls Inherited::Focus and if its true then sets the port's text style and
- // returns true, if it can't be focused returns false.
-
- virtual void Flash();
- // Causes a control to flash with an 8 tick delay.
-
- virtual void Hilite();
- // hilites the current image in the TControl
-
- virtual void HiliteState(Boolean state, Boolean redraw);
- // If our fHilite is not 'state' the set it to 'state' before calling Hilite.
- // Note: hilite is only called if 'redraw is true and we can Focus.
-
- virtual void Inset(const VPoint& delta, Boolean redraw);
- // If we are sizable then offset fInset to 'dh' & 'dv' redrawing if 'redraw' is
- // true.
-
- virtual Boolean IsDimmed();
- // Returns true if the control is currently dimmed.
-
- virtual void GetAdornExtent(VRect& itsAdornExtent);
- // Returns the adorn extent for adorning this view
-
- virtual EventNumber GetEventNumber(); // Override
- // Returns fEventNumber
-
- virtual void SetAdornment(/*CntlAdornment*/ short newAdornment,
- Boolean redraw);
- // Set fAdornment of the 2.0-compatibility adorner.
-
- virtual void GetAdornment(CntlAdornment& itsAdornment);
- // Return fAdornment of the 2.0-compatibility adorner.
-
- virtual void SetPenSize(CPoint newPenSize);
- virtual void GetPenSize(CPoint& itsPenSize);
- // For 2.0-compatible adornment.
-
- virtual void SetInset(const VRect& newInset, Boolean redraw);
- // Set fInset to 'newInset' redrawing if 'redraw' is true.
-
- virtual void InstallColor(const CRGBColor& theColor, Boolean redraw);
- // Sets the color field of our text style record to 'theColor', if 'redraw' then
- // call DrawContents.
-
- virtual void InstallTextStyle(const TextStyle& theTextStyle, Boolean redraw);
- // Sets fTextStyle to 'theTextStyle', if 'redraw' then call DrawContents.
-
- virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
- // Calls Inherited::SetFrame before calling ForceRedraw.
-
- virtual void TrackFeedback(TrackPhase aTrackPhase,
- const VPoint& anchorPoint,
- const VPoint& previousPoint,
- const VPoint& nextPoint,
- Boolean mouseDidMove,
- Boolean turnItOn);
- // Doesn't use the default feedback
-
- virtual void TrackMouse(TrackPhase aTrackPhase,
- VPoint& anchorPoint,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove);
- // Called back from tracking command. Handles tracking of the mouse and then calls
- // DoChoice on TrackRelease.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
-
- VRect fInset; // amount to inset the control portion of
- // the view
-
- EventNumber fEventNumber; // the event number to automatically pass
- // up the line via HandleEvent
-
- short fTextStyleRsrcID; // Rsrc ID of 'TxSt' resource which has
- // TextStyle information.
-
- TextStyle fTextStyle; // the TextStyle to use when rendering
- // this view
-
- Boolean fHilite; // is this view hilited
-
- Boolean fDimmed; // is this view dimmed
-
- Boolean fSizeable; // is the control portion of this view
- // sizeable
-
- Boolean fPreferOutline; // prefer outline fonts?
-
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TCtlMgr: An abstract class that represents a toolbox Control Manager control.
- //----------------------------------------------------------------------------------------
-
- class TCtlMgr : public TControl
- {
- MA_DECLARE_CLASS;
-
- public:
-
- //------------------------------------------------------------------------------------
- // Initialize and Free
- //------------------------------------------------------------------------------------
-
- TCtlMgr();
- // Constructor
-
- void ICtlMgr(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- const CStr255& itsTitle,
- long itsVal,
- long itsMin,
- long itsMax,
- short itsProcID,
- const TextStyle& itsTextStyle = gSystemStyle);// control's text style
- // Initialize procedurally.
-
- virtual ~TCtlMgr();
- // Set the size of control to zero call DisposeControl, then call Inherited::Free.
-
-
- //------------------------------------------------------------------------------------
- // Rest of methods
- //------------------------------------------------------------------------------------
-
- virtual TObject* Clone();
- // Calls Inherited::Clone and then clones owned objects.
-
- virtual void BeInPort(GrafPtr itsPort);
- // Sets the control to be in 'itsPort', by setting the contrlOwner field of the
- // ControlRef.
-
- virtual void CreateCMgrControl(const CStr255& itsTitle,
- long itsVal,
- long itsMin,
- long itsMax,
- short itsProcID);
- // Used to create a new control, calls NewControl to create the control.
-
- virtual void InstallColor(const CRGBColor& theColor, Boolean redraw);
- // Calls Inherited and sets the control color table.
-
- virtual void DimState(Boolean state, Boolean redraw);
- // Set the dim state to 'state' and redrawing it if 'redraw'.
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- // Handles mouse downs in the control by calling TestControl and DoChoice
-
- virtual void Draw(const VRect& area);
- // Draws the control by calling the toolbox routine ShowControl.
-
- virtual PicHandle AsPictForPrinting();
-
- virtual VCoordinate GetLongMax();
- // Returns the current fLongMax value.
-
- virtual VCoordinate GetLongMin();
- // Returns the current fLongMin value.
-
- virtual VCoordinate GetLongVal();
- // Returns the current fLongVal value.
-
- virtual void SetLongMax(VCoordinate itsMax,
- Boolean redraw);
- // Sets fLongMax to 'itsMax', redrawing if required.
-
- virtual void SetLongMin(VCoordinate itsMin, Boolean redraw);
- // Sets flongMin to 'itsMin', redrawing if required.
-
- virtual void SetLongVal(VCoordinate itsVal, Boolean redraw);
- // Sets fLongVal to 'itsVal' redrawing if required.
-
- virtual void SetLongValues(VCoordinate itsVal,
- VCoordinate itsMin,
- VCoordinate itsMax,
- Boolean redraw);
- // Sets all of the values at once, redrawing if required.
-
- virtual short GetHelpState();
- // Override to support help states for controls
-
- //------------------------------------------------------------------------------------
- // Methods to manipulate the Control Manager control values
- //------------------------------------------------------------------------------------
-
- virtual short GetMax();
- // Returns the maximum value of the Control Manager control.
-
- virtual short GetMin();
- // Returns the minimum value of the Control Manager control.
-
- virtual void GetText(CStr255& theText);
- // Returns the controls title, if any.
-
- virtual short GetVal();
- // Returns the current value of the Control Manager control.
-
- virtual short GetVariant();
- // Returns the variant control value for the Control Manager control.
-
- virtual void SetMax(short itsMax, Boolean redraw);
- // While focused sets the maximum value of the Control Manager control to 'itsMax'.
-
- virtual void SetMin(short itsMin, Boolean redraw);
- // While focused sets the minimum value of the Control Manager control to 'itsMin'.
-
- virtual void SetText(const CStr255& itsText, Boolean redraw);
- // Sets the controls title to 'itsText', redrawing if required.
-
- virtual void SetVal(short newVal, Boolean redraw);
- // While focused sets the Control Manager controls value to 'newVal', redrawing if
- // required.
-
- virtual void SetValues(short itsVal,
- short itsMin,
- short itsMax,
- Boolean redraw);
- // While focused sets all the values of the Control Manager control, at once,
- // redrawing if required.
-
- virtual void HiliteState(Boolean state, Boolean redraw);
- // Set the hilite state to 'state', redrawing if required.If hilite state is
- // currently 'state' then does nothing.
-
- virtual void Inset(const VPoint& delta, Boolean redraw);
- // If we are sizable then offset fInset to 'dh' & 'dv' redrawing if 'redraw' is
- // true.
-
- virtual void SetInset(const VRect& newInset, Boolean redraw);
- // Set fInset to 'newInset' redrawing if 'redraw' is true.
-
- virtual void AdjustCtlMgrControl(Boolean redraw);
- // Adjusts ctl mgr control taking into account control area.
-
- virtual Boolean IsCMgrVisible();
- // Returns true if the control is currently visible, false if not.
-
- virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
- // If the control is resizable calls the toolbox routines MoveControl &
- // SizeControl before calling Inherited::SetFrame.
-
- virtual void UpdateCoordinates();// override
- // Keeps the control manager control in synch with any VSpace or QDSpace
- // origin changes.
-
- virtual Boolean SetCMgrVisibility(Boolean beVisible);
- // Sets the visibility of the control to 'isVisible'.
- // Returns old state
-
- virtual void Show(Boolean state, Boolean redraw);
- // Keep the CMgr visibility state synchronized.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
-
- VCoordinate fLongVal; // the current value
-
- VCoordinate fLongMin; // the minimum setting
-
- VCoordinate fLongMax; // the maximum setting
-
- ControlRef fCMgrControl; // the Control Manager Control that is
- // being managed
-
- short fProcID; // Save the procID for use when cloning
-
- short fBitsToShift; // # bits shifted to convert between short
- // and long value.
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TScrollBar: A subclass of TCtlMgr that maps between longint values for our view
- // coordinates and the integers of a toolbox scrollbar.
- //----------------------------------------------------------------------------------------
-
- class TScrollBar : public TCtlMgr
- {
- MA_DECLARE_CLASS;
-
- public:
-
- //------------------------------------------------------------------------------------
- // Initialize and Free
- //------------------------------------------------------------------------------------
-
- TScrollBar();
- // Constructor
- virtual ~TScrollBar();
- // Destructor
-
- void IScrollBar(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- VHSelect itsDirection,
- long itsVal,
- long itsMin,
- long itsMax);
- // Initialize a scrollbar procedurally.
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFields(TStream* aStream); // override
-
- virtual void WriteFields(TStream* aStream); // override
-
- //------------------------------------------------------------------------------------
- // View method overrides
- //------------------------------------------------------------------------------------
- virtual void DeltaValue(VCoordinate delta);
- // Does range checking on 'delta' checking it against fLongMin & fLongMax for the
- // scrollbar.
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- // Handles the mouse down in the various parts of the scrollbar.
-
- virtual void TrackScrollBar(short partCode);
- // Tracks the scrollbar by calling DeltaValue.
-
- virtual void ActionProc(short partCode);
- // Forwarded to from the global routine: ActionProcForTScrollBar which was set as
- // the ScrollBar's action proc. Typically forwards again to TrackScrollBar after
- // bounds checking and Updates before returning to the ScrollBar.
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
-
- VHSelect fDirection; // is this a horizontal or vertical
- // scrollbar
-
- };
-
- //----------------------------------------------------------------------------------------
- // TScrollerScrollBar: A subclass of TScrollBar that is associated with one or more
- // scrollers.
- //----------------------------------------------------------------------------------------
-
- class TScrollerScrollBar : public TScrollBar
- {
- MA_DECLARE_CLASS;
-
- public:
-
- //------------------------------------------------------------------------------------
- // Initialize and Free
- //------------------------------------------------------------------------------------
-
- TScrollerScrollBar();
- // Constructor
-
- void IScrollerScrollBar(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- VHSelect itsDirection,
- long itsMax,
- TScroller* itsScroller);
- // Initialize the scrollbar procedurally.
-
- virtual ~TScrollerScrollBar();
- // If the scrollers are not NULL then first detach the scrollbars from them before
- // freeing the scrollers, then call Inherited::Free.
-
-
- //------------------------------------------------------------------------------------
- // Methods
- //------------------------------------------------------------------------------------
-
- virtual TObject* Clone();
- // Calls Inherited::Clone and then clones owned objects.
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFields(TStream* aStream); // override
-
- virtual void WriteFields(TStream* aStream); // override
-
- //------------------------------------------------------------------------------------
- // Methods
- //------------------------------------------------------------------------------------
-
- virtual void AttachScroller(TScroller* itsScroller);
- // IF 'itsScroller' is not NULL then add it to our list and attach ourselves to it.
-
- virtual void BeInPort(GrafPtr itsPort);
- // Call Inherited::BeInPort and then set our visibility based on the state of the
- // window we are in.
-
- virtual void Activate(Boolean entering);
- // If 'entering' is true then show ourselves, otherwise just call Draw to frame
- // our area.
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- // Handles mouse downs in the scrollbar.
-
- virtual void Draw(const VRect& area);
- // Draws a frame around the controls area before calling Inherited::Draw.
-
- virtual void TrackScrollBar(short partCode);
- // Called to handle tracking of the scrollbar by calling DeltaValue.
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
-
- TList* fScrollers; // the associated scrollers if any
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TControlTracker: A Tracker adapted for tracking controls.
- //----------------------------------------------------------------------------------------
-
- class TControlTracker : public TTracker
- {
- MA_DECLARE_CLASS;
-
- public:
-
- //------------------------------------------------------------------------------------
- // Initialize and Free
- //------------------------------------------------------------------------------------
-
- TControlTracker();
- // Constructor
- virtual ~TControlTracker();
- // Destructor
-
- void IControlTracker(TControl* theControl, const VPoint& itsMouse);
- // Initialize the tracker procedurally.
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
-
- TControl* fControl; // the control being tracked
-
- };
-
- //------------------------------------------------------------------------------------
- // Utility class.
- //------------------------------------------------------------------------------------
-
- class CWhileFocused
- {
- protected:
- void* operator new(size_t size); // prohibit "new CWhileFocused"
- void operator delete(void* obj); // avoid compiler warnings
-
-
- public:
- // Constructor
- CWhileFocused(TCtlMgr* itsCtlMgr,
- Boolean redraw);
-
- ~CWhileFocused();
- // Restores the focus, removes the failure handler.
-
- void Cleanup();
-
- static void CallCleanup(void* context);
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- protected:
- TCtlMgr* fCtlMgr;
- CPoint fOldControlLocation;
- FailInfo fFailInfo; // the failure record that references
- // the failure handling method
- Boolean fRedraw;
- Boolean fWasVisible;
- Boolean fDidFocus;
- };
-
- #endif
-
-